#ifndef     __SCOPE_GUARD_H_INCLUDED__
#define     __SCOPE_GUARD_H_INCLUDED__

#include    <functional>

/**
 * Helper class to do cleanups.
 */
class ScopeGuard {
public:
    ScopeGuard(const std::function<void()> & f) : _f(f), _dismissed(false) {}
    virtual ~ScopeGuard() { if (!_dismissed && _f) _f(); }

    /**
     * Dismiss guard cleanup.
     */
    inline void Dismiss() { _dismissed = true; }

private:
    std::function<void()> _f;
    bool _dismissed;
};

#endif//    __SCOPE_GUARD_H_INCLUDED__